package com.tencent.iov.cowin.befsale.clue;

import com.software.boot.common.util.IpUtil;
import com.software.boot.plugin.config.core.BaseProperties;
import com.software.boot.swagger.EnableSwagger2Doc;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.concurrent.Executor;

@EnableFeignClients(basePackages = {
        "com.tencent.iov.cowin.befsale.clue",
        "com.tencent.cloud.iov.common.fegin"
})
@EnableTransactionManagement
@EnableSwagger2Doc
@Slf4j
@SpringBootApplication(scanBasePackages = {
        "com.tencent.iov.cowin.befsale.clue",
        "com.tencent.cloud.iov.common.serialize",
        "com.tencent.cloud.iov.common.utils",
        "com.tencent.cloud.iov.common.api",
        "com.tencent.cloud.iov.common.crypt.config"
})
@EnableAsync
public class ClueServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClueServiceApplication.class, args);

        String message = String.format("%s站点正常启动，机器IP为：%s，端口为：%s",
                BaseProperties.getProperty("spring.application.name", "scrm-befsale-clue-service"),
                IpUtil.getIp(),
                BaseProperties.getProperty("server.port", "8080"));
        log.info(message);
    }

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer() {
        String applicationName = BaseProperties.getProperty("spring.application.name", "");
        return registry -> registry.config().commonTags("application", applicationName);
    }

    @Bean(name = "threadPoolTaskExecutor")
    public Executor threadPoolTaskExecutor() {
        return new ThreadPoolTaskExecutor();
    }
}
